-- FETCH_WRECKAGE_BONUS

-- 计算冒险者残骸奖励
-- @param user   玩家对象
-- @param bonus  配置的奖励
return function(user, bonus)
    local classId;
    if bonus == "wizard" then
        -- 未获得男巫冈布奥，80%概率获得法袍；否则为60%
        local robeRate = iif(PetM.getMyPet(50), 60, 80);

        local rand = DungeonM.getRandSeed("WIZARD_WRECKAGE");
        if rand % 100 < robeRate then
            classId = 8004;  -- 男巫的法袍
        else
            classId = 7070;  -- 蓝精灵药剂
        end

        return { { 1, classId, 1, }, };
    end

    if type(bonus) == 'table' and #bonus > 0 then
        -- 如果传入了配置的奖励，直接使用
        return bonus;
    end

    -- 获取随机种子
    local randSeed  = DungeonM.getRandSeed("WRECKAGE") % 100;
    local amount;
    -- 全职猎人之证，首次必定获得，仅1次
    local ret = { {1, 8003, 1}, };

    local propertyOccurs = DungeonM.getPropertyOccurs();

    if propertyOccurs[8003] and propertyOccurs[8003] > 0 then
        -- 获取随机种子
        local randSeed1  = DungeonM.getRandSeed("WRECKAGE") % 100;
        local items = { 7285, 7286, 7287, 7288, };

        classId = FormulaM.invoke("FETCH_BY_RAND", items, randSeed1);
        ret = { {1, classId, 1}, };
    else
        DungeonM.statPropertyOccurs(8003);
    end

    -- 奖励火把，50%概率1个，50%概率2个
    if randSeed < 70 then
        amount = 1;
    else
        amount = 2;
    end

    table.insert(ret, { 1, 7000, amount });

    return ret;
end